package demoMod.stsconsole.helpers;

import demoMod.stsconsole.core.AbstractCreature;
import demoMod.stsconsole.monsters.AbstractMonster;
import demoMod.stsconsole.powers.MinionPower;

import java.util.ArrayList;
import java.util.List;

public class MonsterGroup {
    public List<AbstractCreature> monsters = new ArrayList<>();
    private final List<AbstractCreature> toAdd = new ArrayList<>();

    public void spawnMonster(AbstractMonster monster) {
        spawnMonster(null, monster, false, false);
    }

    public void spawnMonster(AbstractCreature source, AbstractMonster monster, boolean isMinion, boolean minionEscapeOnOwnerDeath) {
        toAdd.add(monster);
        monster.usePreBattleAction();
        if (isMinion) {
            monster.applyPower(source, new MinionPower(monster, source).setEscape(minionEscapeOnOwnerDeath));
        }
        monster.rollMove();
    }

    public void addSpawnedMonsters() {
        monsters.addAll(toAdd);
        toAdd.clear();
    }

    public boolean isEnemyBasicallyDead() {
        for (AbstractCreature creature : monsters) {
            if (creature instanceof AbstractMonster && !creature.isDeadOrEscaped()) {
                return false;
            }
        }
        for (AbstractCreature creature : toAdd) {
            if (creature instanceof AbstractMonster && !creature.isDeadOrEscaped()) {
                return false;
            }
        }
        return true;
    }
}
